package ar.uba.fi.algo3.java2d.ejemplo5;

import java.awt.Frame;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Panel;
import java.awt.Dimension;
import java.awt.Color;
import java.awt.Button;

public class VentanaPrincipal extends Frame {

	private static final long serialVersionUID = 1L;
	private Panel panel = null;
	private Panel panelInfo = null;
	private MiCustomComponent customComponent = null;
	private Button botonMover = null;
	private Button botonVolver = null;
	
	private MiCustomComponent getCustomComponent(){
		if(customComponent == null){
			this.customComponent = new MiCustomComponent();
			customComponent.setMinimumSize(new Dimension(70, 70));
			customComponent.setPreferredSize(new Dimension(70, 70));
			customComponent.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					System.out.println("mouseClicked on CustomComponent(" + e.getX() + "," + e.getY() + ")");
				}
			});
		}
		return this.customComponent;
	}
	
	/**
	 * This method initializes panelMutante	
	 * 	
	 * @return java.awt.Panel	
	 */
	private Panel getPanelMutante() {
		if (panel == null) {
			FlowLayout flowLayout = new FlowLayout();
			flowLayout.setAlignment(java.awt.FlowLayout.LEFT);
			panel = new Panel();
			panel.setLayout(flowLayout);
			panel.add(getCustomComponent(), null);
		}
		return panel;
	}

	/**
	 * This method initializes panelInfo	
	 * 	
	 * @return java.awt.Panel	
	 */
	private Panel getPanelInfo() {
		if (panelInfo == null) {
			panelInfo = new Panel();
			panelInfo.setLayout(new FlowLayout());
			panelInfo.setMinimumSize(new Dimension(30, 30));
			panelInfo.setPreferredSize(new Dimension(30, 30));
			panelInfo.setBackground(Color.lightGray);
			panelInfo.add(getBotonMover(), null);
			panelInfo.add(getButtonVolver(), null);
		}
		return panelInfo;
	}

	/**
	 * This method initializes buttonIniciar	
	 * 	
	 * @return java.awt.Button	
	 */
	private Button getBotonMover() {
		if (botonMover == null) {
			botonMover = new Button();
			botonMover.setLabel("Mover");
			botonMover.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					getCustomComponent().setLocation(50, 50);
				}
			});
		}
		return botonMover;
	}

	/**
	 * This method initializes buttonVolver	
	 * 	
	 * @return java.awt.Button	
	 */
	private Button getButtonVolver() {
		if (botonVolver == null) {
			botonVolver = new Button();
			botonVolver.setLabel("Volver");
			botonVolver.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					getCustomComponent().setLocation(10, 10);
				}
			});
		}
		return botonVolver;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		VentanaPrincipal ventana = new VentanaPrincipal();
		ventana.setVisible(true);
	}

	/**
	 * This is the default constructor
	 */
	public VentanaPrincipal() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(300, 200);
		this.setTitle("Java2D - Ejemplo 4");
		this.add(getPanelMutante(), BorderLayout.CENTER);
		this.add(getPanelInfo(), BorderLayout.SOUTH);
		this.addWindowListener(new java.awt.event.WindowAdapter() {
			public void windowClosing(java.awt.event.WindowEvent e) {
				System.out.println("windowClosing()");
				System.exit(NORMAL);
			}
		});
	}

}
